/*

WinClip

   Copyright (C) 2011, Gowtham (gowthamgowtham@gmail.com)

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

*/

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QClipboard>
#include <QSystemTrayIcon>
#include <QLinkedList>
#include <QMimeData>
#include <QDebug>
#include <QSettings>
#include "saveditemsdialog.h"

//#include "ui_SavedItems.h"

namespace Ui {
    class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private:
    Ui::Dialog *ui;
    QClipboard *clipboard;
    int maxItems;
    QMap<long,QString> history;
    QSystemTrayIcon *sysTrayIcon;
    QMenu *menu; // This is the main menu
    QMenu *savedItemsMenu; // This is the menu for saved items
    QMenu *historyListMenu; // This menu is to remove an entry from history list
    QAction *historyRemoveAction;
    QAction *separator;
    QAction *savedItemsAction;
    QIcon *enabledIcon;
    QIcon *disabledIcon;
    QIcon *tickIcon;
    QIcon *emptyIcon;
    SavedItemsDialog *savedItemsDialog;
    QSettings *settings;
    bool firstRun;


    QString trim(QString input);
    bool connectClipboard();
    bool disconnectClipboard();
    void clearHistory();
    void updateHistoryListbox();
    void forgetExtraItems();
    void setClipboard(long id);
    QIcon *getIcon();
    void closeEvent(QCloseEvent *e);
    bool canClose();
    void moveToTop(long id);
    long alreadyInHistory();
    void resetTickIcon();
    void createSavedItemsMenu(const QStringList &list);
    QStringList* getSavedItems();
    long alreadyInSavedItems();
    void readSettings();
    void writeSettings();
    void addRestoredItems(const QStringList &list);
    void showIntro();


public slots:
    void clipboardChangedSlot();
    void listeningToggledSlot();
    void maxItemsChangedSlot();
    void historyClearedSlot();
    void popupMenuClicked();
    void iconActivated(QSystemTrayIcon::ActivationReason reason);
    void hideClicked();
    void linkLabelClicked();
    void savedItemsCmdClicked();
    void historyListMenuRequested(QPoint point);
    void historyRemoveSlot();

};

#endif // DIALOG_H
